using System;
using Reign.Core;

namespace WaterDemo
{
	public class MainWindow : Window
	{
		Game game;
		bool loaded;

		public MainWindow()
		: base("WaterDemo", 512, 512, WindowStartPositions.CenterCurrentScreen, WindowTypes.FrameSizable)
		{
			
		}

		protected override void shown()
		{
			base.shown();
			Console.WriteLine("Init");
			try
			{
				game = new Game(this, null);
				loaded = true;
			}
			catch (Exception e)
			{
				Message.Show("Error", e.Message);
				//Close();
			}
		}

		protected override void closing()
		{
			Console.WriteLine("Closing");
			if (game != null)
			{
				loaded = false;
				game.Dispose();
				game = null;
			}
		}
		
		protected override void update ()
		{
			if (loaded)
			{
				game.Update();
				if (game != null) game.Render();
			}
			
			base.update ();
		}
	}
}

